package com.ultrapower.request;

import java.util.List;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Scan;

import com.sematext.hbase.wd.RowKeyDistributorByHashPrefix;
import com.ultrapower.bean.SqlMetaDataBean;
import com.ultrapower.mapper.SqlMetaDataMapper;
import com.ultrapower.util.HBaseTables;
import com.ultrapower.util.RowKeyUtils;
import com.ultrapower.util.rowkey.RangeOneByteSimpleHash;

public class SqlMetaData_Ver2Table extends BaseRequest {

	int sqlId = 1;
	RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix = new RowKeyDistributorByHashPrefix(
			new RangeOneByteSimpleHash(0, 36, 32));

	public static void main(String[] args) {
		BaseRequest table = new SqlMetaData_Ver2Table();
		table.execute();
	}

	@Override
	void execute() {
		TableName sqlMetaDataTableName = this.getTableName(HBaseTables.SQL_METADATA_VER2_STR);
		SqlMetaDataMapper map = new SqlMetaDataMapper(rowKeyDistributorByHashPrefix);
		this.getHbaseTemplate().get(sqlMetaDataTableName, createGet(), (result) -> {
			List<SqlMetaDataBean> listData = map.mapRow(result, 0);
			if (listData != null) {
				listData.forEach(c -> {
					System.out.println(c);
				});
			}
			return null;
		});
	}

	@Override
	protected Scan createScan() {
		return null;
	}

	protected Get createGet() {
		byte[] rowKey = RowKeyUtils.getMetaInfoRowKey(this.agentId, this.startTime, sqlId);
		Get get = new Get(rowKey);
		get.addFamily(HBaseTables.SQL_METADATA_VER2_CF_SQL);
		return get;
	}

}
